package leetcode1;

//买卖股票的最佳时机
public class leetcode121 {
    class Solution {
        public int maxProfit(int[] prices) {
            int n=prices.length;
            int[][] dp = new int[n][2];
            for (int i = 0; i < prices.length; i++) {
                if(i-1==-1){
                    dp[i][0]=0;
                    dp[i][1]=-prices[i];
                    continue;
                }else{
                    dp[i][0]=Math.max(dp[i-1][0],dp[i-1][1]+prices[i]);
                    dp[i][1]=Math.max(-prices[i],dp[i-1][1]);
                }
            }
            return dp[n-1][0];
        }
    }
}
